#ifndef CHATWINDOW_H
#define CHATWINDOW_H

#include <QMainWindow>
#include <QJsonObject>
#include <QJsonArray>
#include <QListWidgetItem>
#include "addfriendwidget.h"
#include "friendrequestwidget.h"

class TcpClient;
namespace Ui {
class ChatWindow;
}

class ChatWindow : public QMainWindow
{
    Q_OBJECT

private slots:
    void onCurrentFriendChanged(QListWidgetItem *current, QListWidgetItem *previous);
    void on_sendButton_clicked();           //发送数据
    void appendMessageToHistory(const QString& sender, const QString& content,bool isMe);
    void onServerResponse(const QJsonObject& response);
    void onSendFriendRequest(const QString &username, const QString &message);

    void on_addFriend_pushButton_clicked();
    void handleFriendRequestResponse(int fromId, bool accepted);
    void handleFriendRequestResult(const QJsonObject& jsonObj);         //处理是否添加好友在本地

    void on_newFriendpushButton_clicked();

public:
    explicit ChatWindow(TcpClient* client,QWidget *parent = nullptr);
    ~ChatWindow();

    void setCurrentUserInfo(const QJsonObject& userInfo);
    void setFriendsList(const QJsonArray& friends);

private:
    void updateFriendStatus(int id,QString status);

private:
    Ui::ChatWindow *ui;
    QJsonObject m_currentUserInfo;  // 存储当前用户信息
    int m_currentChatFriendId;      //新增成员变量，存储当前聊天好友的ID
    TcpClient* m_tcpClient;         //
    AddFriendWidget* m_addFriendWidget;             //添加好友窗口
    FriendRequestWidget *m_friendRequestWidget;     //处理好友申请窗口

};

#endif // CHATWINDOW_H
